﻿using System;
using System.Text;
using Microsoft.Practices.RecipeFramework;
using EnvDTE;
using Microsoft.Practices.ComponentModel;

namespace SteriaMummert.SharePoint.SoftwareFactoryLite.ValueProviders
{
    [ServiceDependency(typeof(DTE))]
    public class DefaultNamespaceProvider : ValueProvider
    {
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            DTE service = (DTE)this.GetService(typeof(DTE));
            if (service.SelectedItems.Count > 0)
            {
                try
                {
                    SelectedItem item = service.SelectedItems.Item(1);
                    Project p = item.Project;
                    newValue = p.Properties.Item("DefaultNamespace").Value;
                    return true;
                }
                catch(Exception)
                {
                }              
            }
            newValue = null;
            return false;
        }
    }
}
